﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
using Microsoft.Xna.Framework.Graphics;

namespace Core.Graphics.Animations
{
    public class AnimationFrame
    {
        [XmlAttribute()]
        public Tile FrameTile { get { return _FrameTile; } set { _FrameTile = value; } }

        [XmlAttribute()]
        public Point LocationOffset { get { return _LocationOffset; } set { _LocationOffset = value; } }

        [XmlAttribute()]
        public Point SizeOffset { get { return _SizeOffset; } set { _SizeOffset = value; } }

        [XmlAttribute()]
        public float Rotation { get { return _Rotation; } set { _Rotation = value; } }

        protected Tile _FrameTile;
        protected Point _LocationOffset = new Point(0,0);
        protected Point _SizeOffset = new Point(0, 0);
        protected float _Rotation = 0f;

        public AnimationFrame(Tile FrameTile)
        {
            this._FrameTile = FrameTile;
        }

        public AnimationFrame(Tile FrameTile, Point LocationOffset)
        {
            this.FrameTile = FrameTile;
            this.LocationOffset = LocationOffset;
        }

        public AnimationFrame(Tile FrameTile, Point LocationOffset, float Rotation)
        {
            this.FrameTile = FrameTile;
            this.LocationOffset = LocationOffset;
            this.Rotation = Rotation;
        }

        public void Draw(SpriteBatch SpriteBatch, Rectangle Destination)
        {
            //Offset Location of destination rectangle
            Destination.Offset(LocationOffset);

            //change size of destination rectangle
            Destination.Width += SizeOffset.X;
            Destination.Height += SizeOffset.Y;

            //Draw the Tile using the new Rectangle and rotation
            FrameTile.Draw(SpriteBatch, Destination, Rotation);
        }
    }
}
